package com.njitt.bysj.controller;

import com.njitt.bysj.base.BaseController;
import com.njitt.bysj.base.ResultInfo;
import com.njitt.bysj.bean.RoleBean;
import com.njitt.bysj.query.RoleQuery;
import com.njitt.bysj.srevice.RoleService;
import com.njitt.bysj.utils.AssertUtil;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.jws.WebParam;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description: 角色控制器
 * @author: wyj
 * @time: 2022/3/20 17:12
 */
@Controller
@RequestMapping("role")
public class RoleController extends BaseController {
    @Resource
    private RoleService roleService;


    @RequestMapping("toRolePage")
    public String toRolePage() {
        return "role/role";
    }

    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> list(RoleQuery roleQuery) {
        Map<String, Object> map = roleService.roleQuery(roleQuery);
        return map;
    }

    @RequestMapping("toAddOrUpdateRolePage")
    public String toAddOrUpdateRolePage(Integer id, Model model) {
        model.addAttribute("roleId", id);
        return "role/addOrUpdateRole";
    }

    @RequestMapping("add")
    @ResponseBody
    public ResultInfo add(RoleBean roleBean) {
        roleService.addRole(roleBean);
        return success("添加成功");
    }

    @RequestMapping("update")
    @ResponseBody
    public ResultInfo update(RoleBean roleBean) {
        roleService.updateRole(roleBean);
        return success("修改成功");
    }

    @RequestMapping("toGrantPage")
    public String toGrantPage(Integer id, Model model) {

        return "role/grant";
    }

    @RequestMapping("queryAllRoles")
    @ResponseBody
    public List<Map<String, Object>> queryAllRoles() {
        return roleService.queryAllRoles();
    }

    @RequestMapping("queryEmpRolesByEmpId")
    @ResponseBody
    public List<Map<String, Object>> queryEmpRolesByEmpId(Integer empId) {
        return roleService.queryEmpRolesByEmpId(empId);
    }

    @RequestMapping("deleteBatch")
    @ResponseBody
    public ResultInfo deleteBatch(Integer[] ids) {
        roleService.deleteBatchByIds(ids);
        return success("success");
    }

}
